<template>
  <div class="list-table" style="padding-top: 0;">
    <div class="area-header" style="display: flex;justify-content: left;align-items: center;">
      <span class="area-header-title">{{ $t('持股变化') }}</span>
      <div v-if="$store.state.user.userId === '1'" class="add-plus-btn">
        <el-button
          v-hasPermi="['deal:holdingschange:edit']"
          icon="el-icon-circle-plus"
          size="mini"
          type="text"
          style="font-size: 16px"
          @click="addHandle"
        />
      </div>
    </div>

    <el-table v-loading="loading" tooltip-effect="darkTable" :data="dealHoldingsChangeList" border>
      <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('变动时间')" align="center" prop="changeDate" show-overflow-tooltip width="100">
        <template slot-scope="scope">
          {{ parseTime(scope.row.changeDate) }}
        </template>
      </el-table-column>
      <el-table-column :label="$t('事项类型')" align="center" prop="itemType" :formatter="itemTypeFormat" show-overflow-tooltip width="100" />
      <!--<el-table-column :label="$t('公司总股数(万股)/注册资本(万)')" align="center" prop="totalShare" min-width="150">-->
      <!--  <template slot-scope="scope">-->
      <!--    <span class="money-text">{{ moneyFormat(scope.row.totalShare, 'w') }}</span>-->
      <!--  </template>-->
      <!--</el-table-column>-->
      <el-table-column :label="$t('投资主体')" align="center" prop="investorName" show-overflow-tooltip />
      <el-table-column :label="$t('持股数量') + $t('(万股)')" align="center" prop="numberOfShares" show-overflow-tooltip width="130">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.numberOfShares, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('持股比例(%)')" align="center" prop="latestShareholdingRatio" width="160">
        <template slot-scope="scope">
          <span>{{ scope.row.latestShareholdingRatio }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('累计分配金额') + $t('金额单位')" align="center" prop="accumulatedDistributionAmount" show-overflow-tooltip width="130">
        <template slot-scope="scope">
          <span class="money-text">{{ moneyFormat(scope.row.accumulatedDistributionAmount, 'w') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width" width="200">
        <template slot="header">
          <span>{{ $t('操作') }}</span>
          <el-tooltip placement="top">
            <div slot="content">
              {{ $t('不是从持股变化功能添加的数据，不能修改与删除，如需修改请修改来源数据') }}
            </div>
            <i class="el-icon-question" />
          </el-tooltip>
        </template>
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['deal:holdingschange:edit']"
            size="small"
            type="text"
            :icon="scope.row.sourceId ? 'el-icon-view' : 'el-icon-edit'"
            @click="updateHandle(scope.row)"
          >{{ scope.row.sourceId ? $t('查看') : $t('修改') }}</el-button>
          <el-button
            v-if="$store.state.user.userId === '1'"
            v-hasPermi="['deal:holdingschange:remove']"
            size="small"
            type="text"
            icon="el-icon-delete"
            :disabled="!!scope.row.sourceId"
            @click="deleteHandle(scope.row)"
          >{{ $t('删除') }}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改持股变化对话框 -->
    <el-dialog :title="$t('持股变化')" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <dealHoldingsChangeForm ref="dealHoldingsChangeForm" />
    </el-dialog>
  </div>
</template>

<script>
import { listDealHoldingsChange, delDealHoldingsChange, exportDealHoldingsChange } from '@/api/deal/holdingschange/dealHoldingsChange'
import dealHoldingsChangeForm from './dealHoldingsChangeForm.vue'
export default {
    components: {
        dealHoldingsChangeForm
    },
  data() {
      return {
        // 遮罩层
        loading: true,
        // 总条数
        total: 0,
        // 持股变化表格数据
        dealHoldingsChangeList: [],
        // 是否显示弹出层
        formOpen: false,
        // 事项类型字典
        itemTypeOptions: [],
        // 时间范围
        dateRange: [],
        // 查询参数
        queryParams: {
            dealId: this.$route.query.id,
            itemType: undefined,
            pageNum: 1,
            pageSize: 10
        },
        // 表单参数
        form: {},
        // 表单校验
        rules: {
          dealId: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
          sourceId: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
          component: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }]
        }
      }
  },
  created() {
      this.getList()
      this.getDicts('holdings_change_item_type').then(response => {
          this.itemTypeOptions = response.data
      })
  },
  methods: {
    /** 查询持股变化列表 */
    getList() {
        this.loading = true
        listDealHoldingsChange(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
            this.dealHoldingsChangeList = response.rows
            this.total = response.total
            this.loading = false
        })
    },
    // 事项类型字典翻译
    itemTypeFormat(row) {
      return this.selectDictLabel(this.itemTypeOptions, row.itemType)
    },

    // 表单重置
    reset() {
        this.form = {
            id: undefined,
            dealId: undefined,
            sourceId: undefined,
            component: undefined,
            changeDate: undefined,
            itemType: undefined,
            totalShare: undefined,
            investorId: undefined,
            numberOfShares: undefined,
            latestShareholdingRatio: undefined,
            accumulatedDistributionAmount: undefined,
            createBy: undefined,
            createTime: undefined,
            updateBy: undefined,
            updateTime: undefined,
            delFlag: undefined
        }
        this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
        this.queryParams.pageNum = 1
        this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
        this.resetForm('queryForm')
        this.dateRange = undefined
        this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
        this.formOpen = true
        this.$nextTick(() => {
            this.$refs.dealHoldingsChangeForm.init(null)
        })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
        this.formOpen = true
        this.$nextTick(() => {
            // 调用form页面的 init 方法初始化数据
            this.$refs.dealHoldingsChangeForm.init(row)
        })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(function() {
            return delDealHoldingsChange(row.id)
        }).then(() => {
            this.getList()
            this.msgSuccess(this.$t('删除成功'))
        }).catch(function() {
        })
    },
    /** 导出按钮操作 */
    exportHandle() {
        const queryParams = this.queryParams
        this.$confirm(this.$t('是否确认导出?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(function() {
            return exportDealHoldingsChange(queryParams)
        }).then(response => {
            this.download(response.msg)
        }).catch(function() {
        })
    }
  }
}
</script>
<style scoped lang="scss">
.add-plus-btn {
  ::v-deep .el-button el-button--text el-button--mini {
    font-size: 16px;
  }
}
</style>
